package com.ttbj.controller.cost;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ttbj.controller.enums.UserTypeEnum;
import com.ttbj.product.api.CostFacade;
import com.ttbj.product.api.OrderFacade;
import com.ttbj.product.bean.dto.CargoDto;
import com.ttbj.product.bean.dto.BillCostDto;
import com.ttbj.product.bean.dto.OrderDto;
import com.ttbj.product.bean.dto.OwnerDto;
import com.ttbj.product.bean.dto.UserDto;
import com.ttbj.product.bean.dto.ViewData;
import com.ttbj.util.Assert;
import com.ttbj.util.ViewDataUtil;
import com.ttbj.util.ViewModelUtil;

@Controller
@RequestMapping("/applet/cost")
public class CostController {

	@Autowired
	private CostFacade costFacade = null;
 
	/**
	 * 估算搬家费用
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/move/estim.do")
	@ResponseBody
	public ViewData moveCostEstim(HttpServletRequest request, 
			@RequestParam("openId") String openId, // openId
			@RequestParam(value = "discountId", required = false) Long discountId, // 优惠券
			@RequestParam(value = "truckType", required = false) String truckType, // 车辆类型
			@RequestParam(value = "serciveLevel", required = false) String serciveType, // 服务类型
			@RequestParam(value = "driverNum", required = false) Integer orderDriverRequire// 车辆数
	) throws Exception {
		BillCostDto costDto = costFacade.totalMoveCost(null, null, truckType, serciveType, orderDriverRequire);
		return ViewModelUtil.buildSuccess("成功", costDto.getAllFee());
	}

	@RequestMapping("/freight/estim.do")
	@ResponseBody
	public ViewData freightEstim(HttpServletRequest request, @RequestParam("openId") String openId, CargoDto cargoDto, OrderDto orderDto) throws Exception {
		orderDto.openId(openId).setCargoDto(cargoDto);
		Float freightCost = costFacade.getFreightCost(orderDto);
		return ViewModelUtil.buildSuccess("成功", String.valueOf(null == freightCost ? 0f : freightCost));
	}

}
